package core

import (
	"base-web/global"
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"os"
)

func init() {
	mysql := global.BASE_CONFIG.Mysql
	db, err := gorm.Open("mysql", mysql.Username+":"+mysql.Password+"@("+mysql.Path+")/"+mysql.Dbname+"?"+mysql.Config)
	if err != nil {
		fmt.Println("mysql启动失败", err)
		os.Exit(0)
	} else {
		global.BASE_DB = db
		global.BASE_DB.DB().SetMaxIdleConns(mysql.MaxIdleConns)
		global.BASE_DB.DB().SetMaxOpenConns(mysql.MaxOpenConns)
		global.BASE_DB.LogMode(mysql.LogMode)
		fmt.Println("mysql启动成功")
	}
}
